<?php
/**
 * 
 * Internal URI requests interpreter, for cmd: schema 
 * 
 * @package WKernel
 *
 */
require_once 'WKernel/IRequest/Abstract.php';
class WK_IRequest_Cmd extends WK_IRequest_Abstract {
	protected function __run(){
		if(preg_match('/^([0-9a-z_-]+)\/([0-9a-z_-]+)(\?.+)?$/isU', $this->querystr, $matches)) {
			@list($component, $command, $sparams) = array_slice($matches, 1);
			preg_match_all('/&([^&]+)=([^&]+)/si', str_replace('?', '&', $sparams), $matches);
			foreach ($matches[1] as $i => $name) 
				$this->params[$name] = $matches[2][$i];
			
			$oCommand = WK_App::getComponent($component)->getCommand($command, $this->params);
			$this->result = $oCommand->exec();
		}
		else {
			throw new WK_Error('Invalid URI "cmd:'.$this->querystr.'"', WERR_INVALID_INTERNAL_URI);
		}
	}	
}

WK_App::registerUriSchema('cmd', 'WK_IRequest_Cmd');